package ldh.im.fxgui.pane;

import ldh.im.dto.enums.MessageType;

import java.util.function.Supplier;

public enum MessagePaneEnum {
    TextPane(MessageType.Text, ()->new TextMessagePane()),
    RichTextPane(MessageType.RichText, ()->new RichTextMessagePane()),
    ImagePane(MessageType.Image, ()->new ImageMessagePane()),
    FilePane(MessageType.File, ()->new FileMessagePane()),
    AudioPane(MessageType.Audio, ()->new AudioMessagePane()),
    VideoPane(MessageType.Video, ()->new VideoMessagePane()),
    HtmlPane(MessageType.Html, ()->new HtmlMessagePane()),
    WebPane(MessageType.Web, ()->new HtmlMessagePane()),
    UrlPane(MessageType.Url, ()->new UrlMessagePane()),
    ChatPane(MessageType.Chat, ()->new ChatMessagePane()),
    ;

    private MessageType messageType;
    private Supplier<MessagePane> supplier;

    private MessagePaneEnum(MessageType messageType, Supplier<MessagePane> supplier) {
        this.supplier = supplier;
        this.messageType = messageType;
    }

    public MessageType getMessageType() {
        return messageType;
    }

    public MessagePane getMessagePane() {
        return supplier.get();
    }

    public static MessagePaneEnum getByMessageType(MessageType messageType) {
        for(MessagePaneEnum messagePaneEnum : MessagePaneEnum.values()) {
            if (messagePaneEnum.getMessageType() == messageType) {
                return messagePaneEnum;
            }
        }

        throw new RuntimeException("不支持这种类型：" + messageType.name());
    }
}
